package com.wink_172.library.utils

import android.content.Context
import android.os.Environment
import com.wink_172.library.model.Constants.savePath
import org.xutils.x


/**
 *
 * 日志管理工具
 * */
object LogUtil {
    private val TAG = "LogUtil"
    fun getCachePath(context: Context): String? {
        var cachePath: String? = ""
        cachePath =
            if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState() || !Environment.isExternalStorageRemovable()) {
                //外部存储可用
                context.externalCacheDir!!.path
            } else {
                //外部存储不可用
                context.cacheDir.path
            }
        return cachePath
    }
    val cache_path =getCachePath(x.app())
    val savePath_dance_Log =
        cache_path + "/wink-172-logs/"  //该目录不需要存储权限

    val log_name = "测试日志"

    /**
     * 追加到日志文件
     * */
    fun appendToLog(result: String) {

        val time = System.currentTimeMillis()
        val save_path = savePath

        CommonJavaUtils.writeTxtToFile(
            "\n时间：" + DateUtil.longToString(time, DateUtil.FORMAT_TIME) +
                    "\n " + result,
            save_path,
            log_name
        )
    }


}